﻿@model EcBlog.Models.InstallViewModel
@using System.Collections
@using EcBlog.Properties
@{
    ViewBag.Title = ModelLocalization.Install_Web_Site;
    Layout = "~/Areas/Admin/Views/Shared/_InstallLayout.cshtml";
}
@section head {
    <script type="text/javascript">

        $(function () {
            $("#testconnection").click(function () {
                var d = $("#DataSource").val();
                var c = $("#ConnectionString").val();
                $.getJSON("/install/CheckConnection", { dataSource: d, connectionString: c }, function (data) {
                    $("#checkresult").html(data);
                });
            });

            $(".wizard-step:first").fadeIn();
            $("#back-step").hide().click(function () {
                var $step = $(".wizard-step:visible");
                if ($step.prev().hasClass("wizard-step")) {
                    $step.hide().prev().fadeIn();
                    if (!$step.prev().prev().hasClass("wizard-step")) {
                        $("#back-step").hide();
                    }
                }
            });


            $("#next-step").click(function () {
                var $step = $(".wizard-step:visible");
                var validator = $("form").validate();
                var anyError = false;
                $step.find("input").each(function () {
                    if (!validator.element(this)) {
                        anyError = true;
                    }
                });
                if (anyError)
                    return false;

                if ($step.next().hasClass("confirm")) {
                    $.post("/install/confirm", $("form").serialize(), function (r) {
                        $(".wizard-step.confirm").html(r);
                    });
                }

                if ($step.next().hasClass("wizard-step")) {
                    $step.hide();
                    $step.next().fadeIn().show();
                    $("#back-step").show();
                }
                else {
                    $.post("/install/SaveConfigAndRecyleApplication", $("form").serialize(), function (r) {
                        $(".saveprocess").html(r);
                        $.post("/install/confirm", $("form").serialize(), function () {
                            window.setTimeout('$("form").submit();', 5000);
                            $.post("/install/complete", $("form").serialize(), function () {
                                window.location.href = "/";
                            });
                        });
                    });
                }
                return true;
            });
        })

    </script>
    <style type="text/css">
        .wizard-step
        {
            display: none;
            opacity: 100;
        }
        
        .display-field
        {
            font-weight: bold;
        }
        
        .confirm
        {
        }

        .saveprocess { }
    </style>
}
@using (Html.BeginForm())
{ 
    @Html.ValidationSummary(true)
    <div class="wizard-step">
        <table class="editor-table">
            <tr>
                <td colspan="2">
                    <h3>@ModelLocalization.InstallViewModel_Step1</h3>
                </td>
            </tr>
            <tr>
                <td class="editor-label">
                    @Html.LabelFor(model => model.DataSource)
                </td>
                <td class="editor-field">
                    @Html.DropDownListFor(c => c.DataSource, new SelectList((IEnumerable)ViewData["DataSourceList"], "Key", "Value"))
                    @Html.ValidationMessageFor(model => model.DataSource)
                </td>
            </tr>
            <tr>
                <td class="editor-label">
                    @Html.LabelFor(model => model.ConnectionString)
                </td>
                <td class="editor-field">
                    @Html.EditorFor(c => c.ConnectionString)
                    @Html.ValidationMessageFor(model => model.ConnectionString)
                </td>
            </tr>
            <tr>
                <td class="editor-label">
                </td>
                <td class="editor-field">
                    <input type="button" id="testconnection" name="testconnection" value="@ModelLocalization.Test" />
                    <div id="checkresult">
                    </div>
                </td>
            </tr>
        </table>
    </div>
    <div class="wizard-step">
        <table class="editor-table">
            <tr>
                <td colspan="2">
                    <h3>@ModelLocalization.InstallViewModel_Step2</h3>
                </td>
            </tr>
            <tr>
                <td class="editor-label">
                    @Html.LabelFor(model => model.AdminUserName)
                </td>
                <td class="editor-field">
                    @Html.EditorFor(model => model.AdminUserName)
                    @Html.ValidationMessageFor(model => model.AdminUserName)
                </td>
            </tr>
            <tr>
                <td class="editor-label">
                    @Html.LabelFor(model => model.AdminEmail)
                </td>
                <td class="editor-field">
                    @Html.EditorFor(model => model.AdminEmail)
                    @Html.ValidationMessageFor(model => model.AdminEmail)
                </td>
            </tr>
            <tr>
                <td class="editor-label">
                    @Html.LabelFor(model => model.AdminPassword)
                </td>
                <td class="editor-field">
                    @Html.EditorFor(model => model.AdminPassword)
                    @Html.ValidationMessageFor(model => model.AdminPassword)
                </td>
            </tr>
            <tr>
                <td class="editor-label">
                    @Html.LabelFor(model => model.AdminConfirmPassword)
                </td>
                <td class="editor-field">
                    @Html.EditorFor(model => model.AdminConfirmPassword)
                    @Html.ValidationMessageFor(model => model.AdminConfirmPassword)
                </td>
            </tr>
        </table>
    </div>
    <div class="wizard-step">
        <table class="editor-table">
            <tr>
                <td colspan="2">
                    <h3>@ModelLocalization.InstallViewModel_Step3</h3>
                </td>
            </tr>
            <tr>
                <td class="editor-label">
                    @Html.LabelFor(model => model.SiteTitle)
                </td>
                <td class="editor-field">
                    @Html.EditorFor(model => model.SiteTitle)
                    @Html.ValidationMessageFor(model => model.SiteTitle)
                </td>
            </tr>
            <tr>
                <td class="editor-label">
                    @Html.LabelFor(model => model.SiteSlogan)
                </td>
                <td class="editor-field">
                    @Html.TextAreaFor(model => model.SiteSlogan)
                    @Html.ValidationMessageFor(model => model.SiteSlogan)
                </td>
            </tr>
            <tr>
                <td class="editor-label">
                    @Html.LabelFor(model => model.SiteDescription)
                </td>
                <td class="editor-field">
                    @Html.TextAreaFor(model => model.SiteDescription)
                    @Html.ValidationMessageFor(model => model.SiteDescription)
                </td>
            </tr>
            <tr>
                <td class="editor-label">
                    @Html.LabelFor(model => model.SiteUrl)
                </td>
                <td class="editor-field">
                    @Html.TextAreaFor(model => model.SiteUrl)
                    @Html.ValidationMessageFor(model => model.SiteUrl)
                </td>
            </tr>
            <tr>
                <td class="editor-label">
                    @Html.LabelFor(model => model.Author)
                </td>
                <td class="editor-field">
                    @Html.TextAreaFor(model => model.Author)
                    @Html.ValidationMessageFor(model => model.Author)
                </td>
            </tr>
            <tr>
                <td class="editor-label">
                    @Html.LabelFor(model => model.Copyright)
                </td>
                <td class="editor-field">
                    @Html.TextAreaFor(model => model.Copyright)
                    @Html.ValidationMessageFor(model => model.Copyright)
                </td>
            </tr>
        </table>
    </div>
    <div class="wizard-step confirm">
    </div>
    
    <p>
        <input type="button" id="back-step" name="back-step" value="< @ModelLocalization.Back" />
        <input type="button" id="next-step" name="next-step" value="@ModelLocalization.Next >" />
    </p>
    <div class="saveprocess">
    </div>
}